package com.itheima.dao;

import com.itheima.domain.Teacher;

import java.util.ArrayList;

/*
老师数据操作类
增
删
改
查

操作集合
 */
public class TeacherDao {
    private static ArrayList<Teacher> list= new ArrayList<>();

    //增
    public void addTeacher(Teacher teacher){
        list.add(teacher);
    }
    //删
    public void deleteTeacher(String sid){
        int index = getIndex(sid);
        list.remove(index);
    }
    //改
    public void updateTeacher(String sid,Teacher newTea){
        int index = getIndex(sid);
        list.set(index,newTea);
    }


    //查

    public ArrayList<Teacher> findAllTeachers(){
        return list;
    }
    //根据条件查
    public int getIndex(String sid){
        for (int i = 0; i < list.size(); i++) {
            Teacher teacher = list.get(i);
            if(teacher.getSid().equals(sid)){
                return i;
            }
        }
        return -1;
    }

}
